package m

import (
	"iptv_server/v3/src/models/homevideo_model"
	"strings"
)

type DoubanDetail struct {
	DoubanID   string   `json:"doubanID"`
	Director   string   `json:"director"` //
	Poster     string   `json:"poster"`   //x
	Remark     string   `json:"remark"`   //
	Types      []string `json:"types"`    //
	Region     string   `json:"region"`   //
	Plot       string   `json:"plot"`     //描述
	Actor      []string `json:"actor"`    //
	Year       string   `json:"year"`     //
	Name       string   `json:"name"`     //
	HavePoster bool     `json:"have_poster"`
}

// truncate
// func truncate(s string, n int) string {
// 	if len(s) < n {
// 		return s
// 	}
// 	return s[:n]
// }

// truncate
func truncateX(s string, n int) string {
	if len(s) <= n {
		return string(s)
	}
	r := []rune(s)
	if len(r) <= n {
		return string(r)
	}
	return string(r[:n])

}

func (d *DoubanDetail) ToModelDetail() *homevideo_model.Detail {

	m := &homevideo_model.Detail{
		Actors:   truncateX(strings.Join(d.Actor, "/"), 100),
		Type:     truncateX(strings.Join(d.Types, "/"), 100),
		Director: d.Director,
		// poster 海报 已固定文件名存在 vod所在目录
		Remark:      truncateX(d.Remark, 15),
		Area:        truncateX(d.Region, 50),
		Description: truncateX(d.Plot, 280),
		Year:        truncateX(d.Year, 12),
		Name:        truncateX(d.Name, 100),
		DoubanID:    d.DoubanID,
	}

	if len(m.Remark) > 0 {
		m.Remark = "豆瓣:" + m.Remark
	}

	return m
}

/*

{"doubanID": "1863947",
"director": "\u674e\u6dfb\u80dc",
"poster": "https://img1.doubanio.com/view/photo/s_ratio_poster/public/p2565268370.jpg",
"remark": "9.2", "types": ["\u7231\u60c5", "\u6b66\u4fa0", "\u53e4\u88c5"],
"region": "\u4e2d\u56fd\u9999\u6e2f",
"plot": "\u6768\u5eb7\u7684\u513f\u5b50\u6768\u8fc7\uff08\u53e4\u5929\u4e50 \u9970\uff09\u81ea\u5c0f\u88ab\u90ed\u9756\u6536\u517b\uff0c\u90ed\u9756\u5e0c\u671b\u4ed6\u5b66\u597d\uff0c\u4e8e\u662f\u9001\u5230\u4e86\u6843\u82b1\u5c9b\u8ddf\u9ec4\u836f\u8bd7\u5b66\u4e60\u3002\u6768\u8fc7\u5728\u6843\u82b1\u5c9b\u4e0a\u6574\u65e5\u88ab\u90ed\u8299\u548c\u5927\u3001\u5c0f\u6b66\u6b3a\u8d1f\uff0c\u4e00\u6c14\u4e4b\u4e0b\u72ec\u81ea\u51fa\u8d70\u4e86\u3002\u6768\u8fc7\u88ab\u53e4\u5893\u6d3e\u7684\u5c0f\u9f99\u5973\uff08\u674e\u82e5\u5f64 \u9970\uff09\u6536\u7559\uff0c\u8ba4\u5979\u4f5c\u59d1\u59d1\uff0c\u751f\u6d3b\u5728\u6d3b\u6b7b\u4eba\u5893\u91cc\u8ddf\u5c0f\u9f99\u5973\u5b66\u4e60\u6b66\u529f\uff0c\u65e5\u4e45\u5929\u957f\uff0c\u4e24\u4eba\u6e10\u6e10\u4e92\u751f\u60c5\u612b\uff0c\u51b3\u5b9a\u4eca\u751f\u4eca\u4e16\u7ed3\u6210\u592b\u59bb\uff0c\u6c38\u8fdc\u751f\u6d3b\u5728\u53e4\u5893\u3002\u53ef\u60dc\u673a\u7f18\u5de7\u5408\u4e0b\uff0c\u4ed6\u4eec\u6700\u7ec8\u8981\u8d70\u51fa\u6d3b\u6b7b\u4eba\u5893\uff0c\u53bb\u7ecf\u5386\u4e00\u756a\u6c5f\u6e56\u6069\u6028\uff0c\u4e24\u4eba\u6700\u540e\u80fd\u5426\u6709\u60c5\u4eba\u7ec8\u6210\u7737\u5c5e\uff1f",
"actor": ["\u53e4\u5929\u4e50", "\u674e\u82e5\u5f64", "\u767d\u5f6a", "\u9b4f\u79cb\u6866", "\u5085\u660e\u5baa", "\u674e\u7eee\u8679", "\u96ea\u68a8", "\u7b80\u4f69\u7b60", "\u5f20\u53ef\u9890", "\u5218\u4e39", "\u90ed\u5fb7\u4fe1", "\u8a79\u79c9\u7199", "\u6731\u94c1\u548c", "\u9a86\u5e94\u94a7", "\u5434\u5bb6\u8f89", "\u674e\u5bb6\u5f3a", "\u6234\u5fd7\u4f1f", "\u6c5f\u6bc5", "\u9ec4\u4ef2\u5321", "\u5f20\u7ffc", "\u82cf\u7389\u534e", "\u9ece\u8000\u7965", "\u674e\u56fd\u9e9f", "\u5434\u5bb6\u4e50", "\u674e\u5b50\u96c4", "\u4f55\u6d01\u73ca", "\u674e\u8000\u666f", "\u51af\u6653\u6587", "\u5218\u6c5f", "\u674e\u4e3d\u4e3d", "\u9648\u542f\u6cf0", "\u8521\u4e91\u971e", "\u674e\u6842\u82f1", "\u9ec4\u667a\u8d24", "\u5218\u5bb6\u8f89", "\u51af\u7d20\u6ce2", "\u9a8f\u96c4", "\u674e\u5b50\u5947", "\u5173\u83c1", "\u5f20\u9e3f\u660c", "\u7f57\u5170", "\u5f20\u5ef6", "\u9ece\u6c49\u6301", "\u9a6c\u6d77\u4f26", "\u8521\u56fd\u5e86", "\u9c81\u632f\u987a", "\u7126\u96c4", "\u9ea6\u5b50\u4e91", "\u9648\u72c4\u514b", "\u5ed6\u4e3d\u4e3d", "\u9648\u5b89\u83b9", "\u865e\u5929\u4f1f", "\u535a\u541b", "\u6e38\u98d9", "\u5415\u5251\u5149", "\u5b59\u5b63\u537f", "\u533a\u5cb3", "\u7f57\u541b\u5de6", "\u6234\u5c11\u6c11", "\u9093\u6c5d\u8d85", "\u4f0d\u6587\u751f", "\u6c64\u4fca\u660e", "\u5f20\u5b8f\u4f1f", "\u859b\u7eaf\u57fa", "\u4f55\u91d1\u7075", "\u8c2d\u4e00\u6e05", "\u9648\u4e2d\u575a", "\u6881\u5065\u5e73", "\u8c08\u4f69\u73ca", "\u9ec4\u607a\u6b23", "\u6234\u8000\u660e", "\u9646\u5e0c\u626c", "\u9ec4\u5929\u94ce", "\u9ea6\u5609\u4f26", "\u9093\u715c\u8363", "\u5218\u6842\u82b3", "\u90d1\u5bb6\u751f", "\u4e8e\u67ab", "\u77f3\u4e91", "\u5f20\u6c49\u658c", "\u97e9\u5e73", "\u674e\u56fd\u6c85", "\u6731\u4f1f\u8fbe", "\u9648\u5c55\u9e4f", "\u90d1\u96f7", "\u738b\u7ef4\u5fb7", "\u6881\u96ea\u6e44", "\u90ed\u5353\u6866", "\u4f55\u6d69\u6e90", "\u51af\u745e\u73cd", "\u51cc\u6c49", "\u4f55\u7f8e\u597d", "\u6797\u656c\u521a", "\u6881\u94a6\u68cb", "\u6881\u542f\u667a", "\u6881\u5c11\u79cb", "\u674e\u6d77\u751f", "\u675c\u71d5\u6b4c", "\u5f20\u6d4e\u5e73", "\u4e8e\u5c0f\u534e", "\u738b\u542f\u5fb7", "\u9676\u5409\u65b0"],
 "year": "1995", "name": "\u795e\u96d5\u4fa0\u4fa3 \u795e\u96d5\u4fe0\u4fb6", "have_poster": true}
*/
